#!/bin/bash

USAGE="usage: ./check.sh [abstract | chapter [1 | 2| ...] | all]"

INC_DIR=include

LATEX_EXT=.tex

NUM_CHAPTER=6

OPTION='--mode=tex --sug-mode=bad-spellers -d en_US --personal=./aspell.en.pws --dont-suggest'

################################
# check command line arguments #
################################

if [ $# = 0 ]
then
	echo $USAGE
	exit;
fi

if [ $1 = "abstract" ]
then
	echo "Checking  " $1;
	aspell check $OPTION $INC_DIR/$1$LATEX_EXT
	exit;
fi

if [ $1 = "chapter" ]
then
	if [ $2 != 0 -a $2 -lt $NUM_CHAPTER ]
	then
	    fileName=$1$2$LATEX_EXT;
	    echo "Checking  " $fileName;
	    aspell check $OPTION $INC_DIR/$fileName
	    exit;
	fi
fi

if [ $1 = "all" ]
then
	echo "Checking abstract.tex";
   	aspell check $OPTION $INC_DIR/"abstract"$LATEX_EXT
	for ((i=1; i <= $NUM_CHAPTER; i++))
	do
		echo "Checking chapter"$i;
   		aspell check $OPTION $INC_DIR/"chapter"$i$LATEX_EXT
	done
	#echo "This feature is yet supported!"
   	exit;
fi
echo $USAGE
